import java.util.Arrays;

/**
 * @ClassName LC1051
 * @Author ykx
 * @Date 2024/7/6 23:08
 * @Version 1.0
 */
public class LC1051 {
    public static void main(String[] args) {
        LC1051 lc1051 = new LC1051();
        System.out.println(lc1051.heightChecker(new int[]{5, 1, 2, 3, 4}));
    }

    public int heightChecker(int[] heights) {
        int[] result = new int[heights.length];
        System.arraycopy(heights, 0, result, 0, heights.length);
        Arrays.sort(result);

        int count = 0;
        for (int i = 0; i < result.length; i++) {
            count += result[i] == heights[i] ? 0 : 1;
        }
        return count;
    }

}
